package com.yiduan.apollocrm.views.mediators
{
	
	import com.pialabs.eskimo.controls.SkinnableAlert;
	import com.pialabs.eskimo.events.ConfirmEvent;
	import com.yiduan.apollocrm.models.Lead;
	import com.yiduan.apollocrm.services.LeadService;
	import com.yiduan.apollocrm.views.NewLeadView;
	
	import mx.resources.ResourceManager;
	
	import org.robotlegs.mvcs.Mediator;
	
	public class NewLeadMediator extends Mediator
	{
		[Inject]
		public var newLeadView:NewLeadView;		
		[Inject]
		public var leadService:LeadService;
		
		public function NewLeadMediator() {
			super();
		}
		
		override public function onRegister():void {
			trace("NewLeadMediator");
			updateView();
			//this.newLeadView.confirmAddCustomerBtn.addEventListener(ConfirmEvent.CONFIRM,addOrEditLead);
			//this.newLeadView.confirmAddCustomerBtn.addEventListener(ConfirmEvent.CANCEL,cancelNewOrSaveLead);
		}
		
		protected function updateView():void
		{
			if (this.newLeadView.data == null)
			{
				this.newLeadView.currentState = "New";
			}
			else
			{					
				var lead:Lead = this.newLeadView.data as Lead;
				this.newLeadView.firstNameInput.text = lead.firstName;
				this.newLeadView.lastNameInput.text = lead.lastName;
				this.newLeadView.phoneInput.text = lead.phoneNumber;
				this.newLeadView.emailInput.text = lead.email;
				this.newLeadView.companyInput.text = lead.company;
				this.newLeadView.addressInput.text = lead.address;
				this.newLeadView.currentState = "Edit";	
			}
			
		}
		
		protected function addOrEditLead(event:ConfirmEvent):void
		{	
			
			var a :Object = this.newLeadView.data ;
		}
		
		protected function cancelNewOrSaveLead(event:ConfirmEvent):void
		{			
			var a :Object = this.newLeadView.data ;
			
		}
	}
}